home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #9 / Amiga Plus CD - 2004 - No. 09.iso / amigaplus / tools / amigaos4_only / fracblank / source / fracsaver.c < prev    next >
C/C++ Source or Header  |  2004-08-03  |  4KB  |  111 lines

  1. /*
  2. **  FracBlank - AmigaDOS 2.04 commodities utility screenblanker
  3. **
  4. **  Copyright © 1991-1995 by Olaf `Olsen' Barthel
  5. **    All Rights Reserved
  6. **
  7. **  Cosmic flame fractal code derived from xlock source code
  8. **
  9. **  Copyright © 1988-1991 by Patrick J. Naughton.
  10. */
  11.  
  12. #include <datatypes/pictureclass.h>
  13.  
  14. #include <proto/datatypes.h>
  15. #include <proto/exec.h>
  16. #include <proto/graphics.h>
  17. #include <proto/intuition.h>
  18.  
  19. #include "Frac.h"
  20. #include "FracSaver.h"
  21.  
  22. // The process responsible for saving the screen data to the clipboard
  23.  
  24. struct Process *Saver;
  25.  
  26. /* SaverEntry():
  27.  *
  28.  *  This background process handles the job of storing the
  29.  *  contents of the screen in the clipboard.
  30.  */
  31.  
  32. VOID SaverEntry() {
  33.  
  34.   struct BitMap *BitMap;
  35.  
  36.   // That's me
  37.  
  38.   Saver = (struct Process *)IExec->FindTask(NULL);
  39.  
  40.   IExec->ObtainSemaphoreShared(&BlankSemaphore);
  41.  
  42.   IExec->Forbid();
  43.  
  44.   // Create a bitmap to hold a copy of the screen
  45.  
  46.   if (BitMap = IGraphics->AllocBitMap(Width,Height,DisplayDepth,0,RPort->BitMap)) {
  47.     STATIC ULONG Count = 1;
  48.     UBYTE   LocalBuffer[256];
  49.     Object *Image;
  50.     // Copy the contents
  51.     IGraphics->BltBitMap(RPort->BitMap,0,0,BitMap,0,0,Width,Height,0xC0,(1L << DisplayDepth) - 1,NULL);
  52.     // Wait until they have arrived
  53.     IGraphics->WaitBlit();
  54.     IExec->Permit();
  55.     IExec->ReleaseSemaphore(&BlankSemaphore);
  56.     // Build a unique name, in case someone needs it
  57.     SPrintf(LocalBuffer,"FracBlank_%ld×%ld×%ld_%ld",Width,Height,DisplayDepth,Count++);
  58.     // Wrap the bitmap into an image object
  59.     if (Image = IDataTypes->NewDTObject(LocalBuffer,
  60.                                         DTA_SourceType, DTST_RAM,
  61.                                         DTA_GroupID,    GID_PICTURE,
  62.                                         PDTA_NumColors, 1L << DisplayDepth,
  63.                                         PDTA_BitMap,    BitMap,
  64.                                         PDTA_ModeID,    IGraphics->GetVPModeID(&BlankScreen->ViewPort),
  65.                                         TAG_DONE)) {
  66.       struct ColorRegister *ColourMap;
  67.       struct BitMapHeader  *BitMapHeader;
  68.       ULONG  *ColourTab;
  69.       // Get the internal data storage pointers
  70.       if (IDataTypes->GetDTAttrs(Image,
  71.                                  PDTA_BitMapHeader,   &BitMapHeader,
  72.                                  PDTA_ColorRegisters, &ColourMap,
  73.                                  PDTA_CRegs,          &ColourTab,
  74.                                  TAG_DONE) == 3) {
  75.         LONG i;
  76.         // Fill in the header
  77.         BitMapHeader->bmh_Left   = 0;
  78.         BitMapHeader->bmh_Top    = 0;
  79.         BitMapHeader->bmh_Width  = Width;
  80.         BitMapHeader->bmh_Height = Height;
  81.         BitMapHeader->bmh_Depth      = DisplayDepth;
  82.         BitMapHeader->bmh_PageWidth  = Width;
  83.         BitMapHeader->bmh_PageHeight = Height;
  84.         // Fill in the colour tables
  85.         for(i = 0; i < 1L << DisplayDepth; i++) {
  86.           ColourTab[i * 3 + 0]  = Colours->Entry[i].Red;
  87.           ColourTab[i * 3 + 1]  = Colours->Entry[i].Green;
  88.           ColourTab[i * 3 + 2]  = Colours->Entry[i].Blue;
  89.           ColourMap[i].red  = Colours->Entry[i].Red  >> 24;
  90.           ColourMap[i].green  = Colours->Entry[i].Green  >> 24;
  91.           ColourMap[i].blue  = Colours->Entry[i].Blue  >> 24;
  92.         }
  93.         // Put the image into the clipboard
  94.         IIntuition->IDoMethod(Image,DTM_COPY,NULL);
  95.       }
  96.       IDataTypes->DisposeDTObject(Image);
  97.     }
  98.     else IGraphics->FreeBitMap(BitMap);
  99.   }
  100.   else {
  101.     IExec->Permit();
  102.     IExec->ReleaseSemaphore(&BlankSemaphore);
  103.   }
  104.  
  105.   IExec->Forbid();
  106.  
  107.   Saver = NULL;
  108.  
  109. }
  110.  
  111.